home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / asm32.zip / E32.ZIP / CURS_COL.ASM < prev    next >
Assembly Source File  |  1994-03-11  |  2KB  |  89 lines

  1. ; CURS_COL.ASM for E32
  2.  
  3. include    model.inc
  4.  
  5. public    cursor_col
  6. extrn    find_start:near
  7.  
  8. CR    equ    0Dh
  9. TAB    equ    09h
  10.  
  11. include    dataseg.inc
  12. extrn    cursor:dword
  13. extrn    cur_posn:word
  14. extrn    columns:word
  15. extrn    left_margin:word
  16. extrn    dirty_bits:byte
  17. @curseg    ends
  18.  
  19. include    codeseg.inc
  20. ;
  21. ; compute the correct column for the cursor.  No
  22. ; inputs.  On exit, cur_posn is set and DX has the row/col
  23. ;
  24. cursor_col    proc    near
  25.     push    ebp
  26.     push    edi
  27.     mov    esi,cursor
  28.     call    find_start
  29.     mov    ecx,cursor
  30.     sub    ecx,esi
  31.  
  32. ; set DL = -columns so I can use ZF as a flag to adjust left_margin
  33.     mov    dl,byte ptr columns
  34.     neg    dl
  35.     jecxz    col_done
  36.  
  37. ; use a similar trick for margin_count
  38.     mov    di,left_margin    ; DI = margin_count
  39.     neg    di
  40.  
  41. ; move constants to registers for speed
  42.     mov    bp,ds        ; data segment
  43.     shl    ebp,16
  44.     mov    bp,fs
  45.     mov    dh,CR
  46.     mov    bx,8
  47.     mov    ah,TAB
  48.  
  49. cursor_loop:
  50.     mov    ds,bp
  51.     lodsb
  52.     rol    ebp,16
  53.     mov    ds,bp
  54.     rol    ebp,16
  55.  
  56.     cmp    al,dh        ; DH = CR
  57.     je    short col_done
  58.     cmp    al,ah        ; AH = TAB
  59.     jne    short not_a_TAB
  60.  
  61.     or    di,00000111b    ; DI = margin_count
  62.     js    short not_a_tab
  63.     or    dl,00000111b
  64. not_a_TAB:
  65.     inc    di        ; DI = margin_count
  66.     jle    short out_of_window    ; increment column only if margin_count > 0 
  67.     inc    dl        ; we're at next column now
  68.     jnz    short out_of_window
  69.     add    left_margin,bx    ; adjust left_margin if column = 0
  70.     add    di,bx        ; DI = margin_count
  71.     sub    dl,bl
  72.     or    dirty_bits,1
  73.  
  74. out_of_window:
  75.     loop    cursor_loop
  76. col_done:
  77.     add    dx,columns    ; normalize
  78.  
  79. column_ok:
  80.     clc
  81.     mov    byte ptr cur_posn,dl    ; store the column
  82.     pop    edi
  83.     pop    ebp
  84.     ret
  85. cursor_col    endp
  86.  
  87. @curseg    ends
  88.     end
  89.